<?php
header('Content-type: text/xml');
require('setup.php');
include 'db.php';
$smarty = new Smarty_pigier();
session_start();
if (!$_SESSION['_type']==2) {
	header("location:index.php");
}
else {
	$conn=connectDB();
	$result=selectCategories($_POST['filiere'],$_POST['annee']);
	$arrcategories=array();
	$idcategorie=0;
	while ($row = mysql_fetch_array($result)) {
		$arrcategories[$row['id_categorie']]=$row['nomcategorie'];

		$idcategorie = $row['id_categorie'];
	}
	if ($idcategorie!=0) {
		$result=selectcoursByIdCategorie($idcategorie);
		$arr=array();
		$idcour=0;
		while ($row = mysql_fetch_array($result)) {
			$arr[$row['id_cours']]=$row['nomcours'];
			if ($idcour==0) {
				$idcour=$row['id_cours'];
			}
			//array_push($arr, $row['nomcours']);
		}
		$idcour=1;
		if ($idcour!=0) {
			$resultfichier = selectCourfiles($idcour);
			$arrayoffile = array();
			while ($row = mysql_fetch_array($resultfichier)) {
				array_push($arrayoffile, $row);
				//array_push($arr, $row['nomcours']);
			}
			$smarty->assign('fichiercours', $arrayoffile);

		}
		$smarty->assign('cours', $arr);
	}
	$smarty->assign('data', $arrcategories);
	$smarty->display('xmlcategories.tpl');
}
?>
